@extends('layouts.default')
@section('content')
@include('modules.thanhmenu')
<?php
if(HomeController::checkInTime('xoadt')){
    
//ds de tai
$detais = new TBMXoaDeTai();
$detais = $detais->show(Session::get('infor.idbm')[0], $idhknk[0]->id);
//ds nien khoa
$nien_khoas = new HomeController();
$nien_khoas = $nien_khoas->nienKhoa();
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="danhsachhp">
    <tr>
        <td colspan="5" class="btop brt" style="background: #ffffcc;padding:5px;font-size: 14px; font-weight: bold">
            <form action="<?= URL."tbm/6/xoadt"; ?>" method="get" name="frmLK">
                Niên khóa:&nbsp;
                <select name="txtNienKhoa" id="txtNienKhoaId">
                    <?php
                    foreach ($nien_khoas as $nien_khoa) {
                        ?>
                        <option value="<?= $nien_khoa->nien_khoa ?>"<?php if($idhknk[0]->nien_khoa == $nien_khoa->nien_khoa) echo "selected='selected'"; ?>><?= $nien_khoa->nien_khoa ?></option>
                        <?php
                    }
                    ?>
                </select>&nbsp;
                Học kì: 
                <select name="txtHocKy" id="txtHocKyId">
                    <option value="1" <?php if($idhknk[0]->hoc_ky == '1') echo "selected='selected'"; ?>>1</option>
                    <option value="2" <?php if($idhknk[0]->hoc_ky == '2') echo "selected='selected'"; ?>>2</option>
                </select>&nbsp;
                <input type="submit" name="butonLK" class="button_css" style='font-size: 14px' value="Liệt kê"/>
            </form>
        </td>
    </tr>
    <tr> 
        <td colspan="5" class="cm_footer btop brt" style="color:#fff; font-size: 14px; font-weight: bold">
            Danh sách đề tài không được đăng ký
        </td>   
    </tr>
    <tr>  
        <td class="title-danhsachhp" width="10%">
            STT
        </td>
        <td class="title-danhsachhp" width="20%">
            Mã đề tài
        </td>
        <td class="title-danhsachhp" width="40%">
            Tên đề tài
        </td>
        <td class="title-danhsachhp"  width="10%">
            Xem chi tiết
        </td>
        <td class="title-danhsachhp brt" width="20%">
           Tác Vụ
        </td>
    </tr>	
<?php
if(count($detais) != 0)
{
$stt = 0;
foreach ($detais as $detai) {
    ?>
        <tr <?php if($stt%2==1){ echo "style='background:#ccc'";}?>>
            <td>
        <?= ++$stt ?>
            </td>
            <td>
                <?= $detai->ma_so_de_tai ?>
            </td>
            <td>

                <?= $detai->ten_de_tai ?>
            </td>
            <td>
                <img src="<?= URL ?>public/images/icon_view.png" onclick='xemChiTiet(<?= $detai->id ?>)' title="Xem chi tiết"/>
            </td>
            <td class="brt">
                <input type='checkbox' value='tacVu' id="tacVuId_<?= $detai->id ?>" onclick="confirmXoa('<?=$detai->id?>', '<?=$detai->ma_so_de_tai?>','<?=$detai->trang_thai?>');"  title='Liệt kê' <?php if ($detai->trang_thai != 1) echo "checked='checked'" ?>/>
                &nbsp;
                <img src="<?=URL?>/public/images/delete.png" width="20px" alt="Xóa" title="Xóa cứng" onclick="xoaCungDeTai('<?=$detai->id?>','<?=$detai->ma_so_de_tai?>');"/>
            </td>
        </tr>	
    <?php
        }
}
else
{
?>
        <tr>
            <td colspan="5" class="brt" style="padding:5px;font-size: 13px;font-weight: bold">
                Không có đề tài.
            </td>
        </tr>
        <?php
}
        ?>
</table>
<br/>
<form method="post" action="" name="frmLietKeDTXoa" id="frmLietKeDTXoaId">
<?php echo Form::token(); ?>
    <input type="hidden" name="txtNienKhoa" id="txtNienKhoaId" value=""/>
    <input type="hidden" name="txtHocKy" id="txtHocKyId" value=""/>
</form>
<form method="post" action="<?=URL?>tbmXoaDeTai" name="frmXoaDeTai" id="frmXoaDeTaiId">
<?php echo Form::token(); ?>
    <input type="hidden" name="txtIdDeTai" id="txtIdDetaiId" value=""/>
    <input type="hidden" name="txtTacVu" id="txtTacVuId" value=""/>
</form>  
<form method="post" action="<?=URL?>tbmXoaDeTaiCung" name="frmXoaDeTaiCung" id="frmXoaDeTaiCungId">
<?php echo Form::token(); ?>
    <input type="hidden" name="txtIdDeTai" id="txtIdDetaiId" value=""/>
</form>  
<script type='text/javascript'>
    function confirmXoa(id, ms, giatritruoc) {
        var check=false;
        if(giatritruoc != '1'){
            check = true;
        }
        if (confirm('Xác nhận thao tác xóa mềm đề tài '+ms+' này?')) {
                xoaDeTai(id, !check);
        }
        else
        {
            document.getElementById('tacVuId_' + id).checked = check;
        }
    }
    function xoaDeTai(id, check) {
        document.frmXoaDeTai.txtIdDeTai.value = id;
        document.frmXoaDeTai.txtTacVu.value = check;
        document.frmXoaDeTai.submit();

    }
    function xoaCungDeTai(idDeTai,msDeTai)
    {
        if (confirm('Xác nhận thao tác xóa cứng đề tài '+msDeTai+' này?\nLưu ý:thực hiện thao tác này đề tài sẽ bị xóa hoàn toàn khỏi hệ thống!')) {
        document.frmXoaDeTaiCung.txtIdDeTai.value = idDeTai;
        document.frmXoaDeTaiCung.submit();
        }
    }
    function xemChiTiet(idDeTai){
        location.href='<?=URL?>tbm/6/xemdt/'+idDeTai;
    }
</script>
<?php
}
else
{
   echo "<script>alert('Chưa đến thời gian xóa đề tài!');</script>";   
}
?>
@stop

